<?php


namespace App\Api\Manages;


class Common
{

    public static function curl_request($url, $post = true, $params = [], $https = true)
    {
        //初始化请求
        $ch = curl_init($url);
        //默认是get请求。如果是post请求 设置请求方式和请求参数
        if ($post) {
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
        }
        //如果是https协议，禁止从服务器验证本地证书
        if ($https) {
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        }
        //发送请求，获取返回结果
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $res = curl_exec($ch);
        /*if(!$res){
            $msg = curl_error($ch);
            dump($msg);die;
        }*/
        //关闭请求
        curl_close($ch);
        return $res;
    }




}